# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=smbnetfs
pkgver=0.6.3
pkgrel=5
pkgdesc="small C program that mounts Microsoft network neighborhood in single directory."
arch=('loong64' 'x86_64')
url="http://smbnetfs.sourceforge.net/"
license=('GPL')
depends=('fuse2' 'smbclient')
backup=('etc/smbnetfs/.smb/smb.conf'
	'etc/smbnetfs/.smb/smbnetfs.conf'
	'etc/smbnetfs/.smb/smbnetfs.auth'
	'etc/smbnetfs/.smb/smbnetfs.host')
install=smbnetfs.install
options=(docs)
source=(https://downloads.sourceforge.net/smbnetfs/$pkgname-$pkgver.tar.bz2
	conf-smbnetfs
	smbnetfs.service
	smbnetfs.sysusers
  smbnetfs.tmpfiles)
sha256sums=('eac37b9769fbe9c3f4baf3eb64c61a6b59ad4f2aa05dfddcba5a1ac4adf4d560'
            'ca3b686c37fe77193e8df86efcaadb8fe809dfaa8cd62effde6b038af07ea226'
            'f78368434d9abc56cd333ec157a7ad82a6fa54555e1f5b786e8294b394be0b7b'
            '142865e5292756498c644a7fd7bf00ebe689cb3c712e582fa0f10fac105b6ab1'
            'ca042e7a0a26d9e2a0ab1cd590bdd0385ab60fdc46a437a38af4c0a12b9a27a3')

prepare() {
  cd "$srcdir"/$pkgname-$pkgver
  sed -i '/xattr.h/d' src/function.c
}

build() {
  cd "$srcdir"/$pkgname-$pkgver
  sed -i 's|libsmbclient.h|samba-4.0/libsmbclient.h|g' \
    src/smb_conn_srv.c src/smb_conn_proto.h src/function.c src/main.c src/event.c
  [ $NOEXTRACT -eq 1 ] || ./configure --prefix=/usr --docdir=/usr/share/doc/smbnetfs --with-gnome-keyring=no
  make
}

package() {
  cd "$srcdir"/$pkgname-$pkgver

  make DESTDIR="$pkgdir" install

  mv "$pkgdir"/usr/share/doc/smbnetfs* "$pkgdir"/usr/share/doc/smbnetfs

  mkdir -p "$pkgdir"/etc/smbnetfs/.smb
  install -Dm644 "$srcdir/$pkgname.sysusers" \
    "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
  install -Dm644 "$srcdir/$pkgname.tmpfiles" \
    "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
  install -m0644 "$srcdir"/$pkgname-$pkgver/conf/* "$pkgdir"/etc/smbnetfs/.smb/
  install -Dm0644 "$srcdir"/$pkgname-$pkgver/README "$pkgdir"/usr/share/doc/smbnetfs/README
  install -Dm0644 "$srcdir"/conf-smbnetfs "$pkgdir"/etc/conf.d/smbnetfs
  install -Dm0644 "$srcdir"/smbnetfs.service "$pkgdir"/usr/lib/systemd/system/smbnetfs.service
  touch "$pkgdir"/etc/smbnetfs/.smb/smb.conf
}
